package com.xinzhi.service.impl;

import com.xinzhi.mapper.ForgetMapper;
import com.xinzhi.pojo.User;
import com.xinzhi.service.ForgetService;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ForgetImpl implements ForgetService {
    @Autowired
    private ForgetMapper forgetMapper;
    @Override
    public Result getByPassord(String username, String identity_card) {
       //对传过来的数据进行判空
        if (username == null && identity_card == null)
            return  Result.error("用户名和身份证号不能为空");
        //身份证号进行正则表达式判断
        if (!identity_card.matches("^(\\d{15}|\\d{17}[\\dXx])$"))
            return  Result.error("身份证号格式错误");
        User user = forgetMapper.selectUsername(username, identity_card);
        return user !=null? Result.ok("验证成功"):Result.error("验证失败");
    }
}
